home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 74 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.5 KB

  1. Path: news.kei.com!ub!newserve!rebecca!rpi!not-for-mail
  2. From: yossef@ird.scitex.com (Yossef Halakhmi)
  3. Newsgroups: comp.lang.c++.moderated,comp.lang.c++,comp.os.ms-windows.programmer.misc
  4. Subject: Re: STL loops through a list with one element more than once!  Why?
  5. Date: 1 Jan 1996 17:47:33 -0000
  6. Organization: Scitex Corp.
  7. Sender: cppmods@netlab.cs.rpi.edu
  8. Approved: Dietmar.Kuehl@uni-konstanz.de
  9. Message-ID: <4c96nl$1tr@netlab.cs.rpi.edu>
  10. References: <4c1n8o$2jn@netlab.cs.rpi.edu>
  11. NNTP-Posting-Host: netlab.cs.rpi.edu
  12.  
  13. X-Original-Date: 31 Dec 1995 07:54:48 GMT
  14.  
  15. In article <4c1n8o$2jn@netlab.cs.rpi.edu>, Bowden Wise <wiseb@cs.rpi.edu> wrote:
  16.  
  17. > BOOL DDETopic::DelAllItems ()
  18. > {
  19. >    for (_itemIter  =   _itemList.begin();
  20. >         _itemIter  !=  _itemList.end();
  21. >         _itemIter++)
  22. >    {
  23. >       _itemList.erase (_itemIter);
  24. >    } 
  25. >    return TRUE;
  26. > }
  27.  
  28.  
  29.  
  30. After any one 'erase' your list is changed and iterator doesn't point to
  31. the objrct that you want . _itemList.end() also will point on something new.
  32. And not to the old value of  _itemList.end() which you have in 
  33. 'for' .
  34. If  you want to erase all elements in list/array then use 
  35. erase(iterator forst, iterator last) mem-function
  36.  
  37.     [ comp.lang.c++.moderated is a moderated newsgroup.  Submit articles ]
  38.     [  to <c++-submit@netlab.cs.rpi.edu>.  The moderation policy can be  ]
  39.     [   retrieved from <http://netlab.cs.rpi.edu/~cppmods/guide.html>.   ]
  40.     [    Moderators can be reached at: c++-request@netlab.cs.rpi.edu.    ]
  41.